<!--
 * @Date: 2020-04-22 11:13:17
 * @LastEditors: 黄栋
 * @LastEditTime: 2020-04-23 09:49:19
 * @FilePath: /cloudAdmin/src/views/market/promotion/member/components/moduleDetail.vue
 -->
<template>
  <!--统一的编辑和新增 -->
  <el-dialog :close-on-click-modal="false" :visible.sync="visible" :title="editForm.name">
    <el-form label-width="120px">
      <div v-if="editForm.name=='签到送积分'">
        <el-form-item label="是否能补签">
          <el-radio v-model="editForm.is_mend" :label="1">可补签</el-radio>
          <el-radio v-model="editForm.is_mend" :label="2">暂不可补签</el-radio>
        </el-form-item>
        <el-form-item label="补签扣除积分">
          <el-input v-model="editForm.mend_num"></el-input>
          <div>用户每补一次签，扣除一次上面设置的补签积分</div>
        </el-form-item>
        <el-form-item label="签到规则">
          <el-input type="textarea" v-model="editForm.details"></el-input>
        </el-form-item>
      </div>
      <div v-if="editForm.name=='购物送积分'">
        <el-form-item label="赠送比例">
          <el-input v-model="editForm.integral"></el-input>
          <div>实际赠送积分等于商品价格(按照等价换算成积分)×赠送比例，赠送比例越高赠送积分越多。</div>
        </el-form-item>
      </div>
      <div v-if="editForm.name=='积分抵扣'">
        <el-form-item label="积分等价">
          <el-input v-model="editForm.score"></el-input>
          <div>积分等价指的是1元人名币可以等价的积分数量</div>
        </el-form-item>
        <el-form-item label="抵扣比例">
          <el-input v-model="editForm.score_num"></el-input>
          <div>即抵扣金额/订单总金额，抵扣比例越高，抵扣金额越多</div>
        </el-form-item>
      </div>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">取消</el-button>
      <el-button size="small" type="primary" @click="editFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>
 
 <script>
export default {
  data() {
    return {
      visible: false,
      editForm: { id: "" }
    };
  },
  methods: {
    /**初始化数据 */
    initData(id) {
      if (id) {
        this.editForm.id = id;
        this.$http({
          url: this.$http.adornUrl("market/score/get_module_set"),
          method: "post",
          data: this.$http.adornData({ id: id })
        }).then(res => {
          if (res.code == 200) {
            this.editForm = Object.assign({}, this.editForm, res.data);
            this.visible = true;
          } else {
            this.$message.error(res.message);
          }
        });
      } else {
        /**初始化表单 */
        this.editForm = {
          name: "",
          module_code: "",
          description: "",
          score: "",
          integral: "",
          min_price: "",
          details: "",
          is_mend: "",
          mend_num: "",
          is_month_clear: "",
          status: 1
        };
        this.visible = true;
      }
    },
    /**新增/编辑 数据 */
    editFormSubmit() {
      this.$http({
        url: this.$http.adornUrl("market/score/edit_module_set"),
        method: "post",
        data: this.$http.adornData({
          id:this.editForm.id,
          score_num:this.editForm.score_num||'',
          score:this.editForm.score||'',
          integral:this.editForm.integral||'',
          min_price:this.editForm.min_price||'',
          details:this.editForm.details||'',
          is_mend:this.editForm.is_mend||'',
          mend_num:this.editForm.mend_num||'',
          status:this.editForm.status||'',
        })
      }).then(res => {
        if (res.code == 200) {
          this.$message({
            message: res.message,
            type: "success",
            duration: 1000,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        } else {
          this.$message.error(res.message);
        }
      });
    }
  }
};
</script>
 
 <style>
</style>
